﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _2022Learning._03DesignPattern
{
    /// <summary>
    /// 三大工厂
    /// </summary>
    public class FactoryPattern
    {
        public static MobilePhone GetMobile(string phoneMobile)
        {
            switch (phoneMobile)
            {
                case "苹果":
                    return new IPhobe();
                case "小米":
                    return new XimiPhobe();
                case "华为":
                    return new HUAWeiPhobe();
                default:
                    return new HUAWeiPhobe();
            }
        }
    }

    #region 简单工厂：根据传入的入参来判断应该生成哪个对象
    public abstract class MobilePhone
    {
        public abstract void PhonePrint();
    }

    public class IPhobe : MobilePhone
    {
        public override void PhonePrint()
        {
            Console.WriteLine("我是烂苹果");
        }
    }

    public class XimiPhobe : MobilePhone
    {
        public override void PhonePrint()
        {
            Console.WriteLine("我是疯小米");
        }
    }

    public class HUAWeiPhobe : MobilePhone
    {
        public override void PhonePrint()
        {
            Console.WriteLine("我是大华为");
        }
    }
    #endregion

    #region 工厂方法：每个对象都有一个特定的工厂，后续在来一个产品，都需要新建一个产品类和特定工厂，主要是解决“单个对象”的需求变化


    /// <summary>
    /// 抽象汽车类
    /// 抽象类可以有实例方法
    /// </summary>
    public abstract class Car
    {
        /// <summary>
        /// 汽车gou
        /// </summary>
        public abstract void Go();
    }

    /// <summary>
    /// 红旗车
    /// </summary>
    public class HQCar : Car
    {
        public override void Go()
        {
            Console.WriteLine("红旗车正在滴滴滴");
        }
    }

    /// <summary>
    /// 奥迪车
    /// </summary>
    public class AoDiCar : Car
    {
        public override void Go()
        {
            Console.WriteLine("奥迪车正在滴滴滴");
        }
    }

    /// <summary>
    /// 工厂方法工厂
    /// </summary>
    public abstract class Factory
    {
        public abstract Car CreatCar();
    }

    /// <summary>
    /// 红旗车专用工厂
    /// </summary>
    public class HQFactory : Factory
    {
        public override Car CreatCar()
        {
            return new HQCar();
        }
    }

    /// <summary>
    /// 奥迪车专用工厂
    /// </summary>
    public class AudiFactory : Factory
    {
        public override Car CreatCar()
        {
            return new AoDiCar();
        }
    }
    #endregion

    #region 抽象工厂：主要是解决“系列对象”的需求变化，也就是对特定的工厂有特殊的需求，抽象工厂就是为了创建一些列的产品，宫女长方法的加强版,相对而言，用的比较多的就是抽象工厂
    public abstract class AbstractFactory
    {
        public abstract Roof CreateRoof();
        public abstract Floor CreateFloor();
        public abstract Window CreateWindow();
        public abstract Door CreateDoor();

    }

    /// <summary>
    /// 房顶抽象类
    /// </summary>
    public abstract class Roof
    {
        public abstract void Create();
    }

    /// <summary>
    /// 地板抽象类
    /// </summary>
    public abstract class Floor
    {
        public abstract void Create();
    }

    /// <summary>
    /// 窗户抽象类
    /// </summary>
    public abstract class Window
    {
        public abstract void Create();
    }

    /// <summary>
    /// 门抽象类
    /// </summary>
    public abstract class Door
    {
        public abstract void Create();
    }

    /// <summary>
    /// 欧式风格家具工厂类
    /// </summary>
    public class EuropeanFactory : AbstractFactory
    {
        public override Door CreateDoor()
        {
            return new EuropeanDoor();
        }

        public override Floor CreateFloor()
        {
            return new EuropeanFloor();
        }

        public override Roof CreateRoof()
        {
            return new EuropeanRoof();
        }

        public override Window CreateWindow()
        {
            return new EuropeanWindow();
        }
    }

    public class EuropeanRoof : Roof
    {
        public override void Create()
        {
            Console.WriteLine("创建欧式房顶");
        }
    }

    public class EuropeanFloor : Floor
    {
        public override void Create()
        {
            Console.WriteLine("创建欧式地板");
        }
    }

    public class EuropeanWindow : Window
    {
        public override void Create()
        {
            Console.WriteLine("创建欧式窗户");
        }
    }

    public class EuropeanDoor : Door
    {
        public override void Create()
        {
            Console.WriteLine("创建欧式房门");
        }
    }
    #endregion



}
